package com.hulk.dryad.manage.config;

import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.validation.MessageInterpolatorFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

import javax.validation.Validator;

/**
 * @author hulk
 * @version 1.0
 * @date 2020/10/20 6:02 下午
 */
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter(MessageSourceConfig.class)
@RequiredArgsConstructor
public class ValidatorConfig {

	private final MessageSource messageSource;

	@Bean
	public Validator validator() {
		LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
		factoryBean.getValidationPropertyMap().put("hibernate.validator.fail_fast", "true");
		factoryBean.setValidationMessageSource(messageSource);
		return factoryBean;
	}
}
